﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace SeleniumToolkit.Config
{
    /// <summary>
    /// Defines a user extension (JavaScript file) to be included in the Selenium RC Host
    /// </summary>
    public class UserExtensionElement : ConfigurationElement
    {
        static UserExtensionElement()
        {
            PropertyCollection = new ConfigurationPropertyCollection();
            NameProperty = new ConfigurationProperty(NameKey, typeof(string), null, ConfigurationPropertyOptions.IsKey);
            PathProperty = new ConfigurationProperty(PathKey, typeof(string), null, ConfigurationPropertyOptions.None);

            PropertyCollection.Add(NameProperty);
            PropertyCollection.Add(PathProperty);
        }

        #region Constructors
        /// <summary>
        /// Default Constructor
        /// </summary>
        public UserExtensionElement()
        {
        }
        /// <summary>
        /// Constructor with Name and Path
        /// </summary>
        /// <param name="name">Name of the user extension</param>
        /// <param name="path">Path to the user extension</param>
        public UserExtensionElement(string name, string path)
        {
            Name = name;
            Path = path;
        } 
        #endregion

        #region Properties

        /// <summary>
        /// Friendly name of the user extension
        /// </summary>
        [ConfigurationProperty(NameKey, IsKey = true)]
        public string Name
        {
            get { return (string)base[NameProperty]; }
            set { base[NameProperty] = value; }
        }

        /// <summary>
        /// Path to the Javascript File
        /// </summary>
        [ConfigurationProperty(PathKey)]
        public string Path
        {
            get { return (string)base[PathProperty]; }
            set { base[PathProperty] = value; }
        }

        /// <summary>
        /// Gets the 
        /// </summary>
        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return PropertyCollection;
            }
        } 
        #endregion

        private static readonly ConfigurationProperty NameProperty;
        private const string NameKey = "name";
        private static readonly ConfigurationProperty PathProperty;
        private const string PathKey = "path";

        private static readonly ConfigurationPropertyCollection PropertyCollection;
    }
}
